<!-- !+tabs -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/react.js"></script>
    <script src="js/browser.min.js"></script>
    <script src="js/react-dom.js"></script>
</head>
<body>
    <div id="example"></div>

    <script type="text/babel">

        var MyButton = React.createClass({
            handleClick:function(){
                // console.log('btn is clicked');
                // 希望在按钮按下时 能够执行通过func属性所传递来的方法
                this.props.func('张三');

            },
            render:function(){
                return <button 
                onClick={this.handleClick}>
                    {this.props.btnName}
                </button>
            }
        });

        var MyForm = React.createClass({
            login:function(uname){
                console.log(uname+'登录成功');
            },
            register:function(uname){
                console.log(uname+'注册成功');
            },
            render:function(){
                return <div>
                    <MyButton btnName='登录'
                     func={this.login}>
                    </MyButton>
                    <MyButton btnName='注册'
                    func={this.register}>
                    </MyButton>
                </div>
            }
        });

        ReactDOM.render(
            <MyForm></MyForm>,
            document.getElementById('example')
        );
    </script>
</body>
</html>